home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.src.lzh / relay / hdrparse.c < prev    next >
C/C++ Source or Header  |  1989-07-08  |  2KB  |  91 lines

  1. /*
  2.  * Usenet header parsing and remembering.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #ifndef AMIGA
  8. #  include <sys/types.h>
  9. #endif /* AMIGA */
  10. #include "libc.h"
  11. #include "news.h"
  12. #include "headers.h"
  13. #include "hdrint.h"
  14.  
  15. /*
  16.  * Reset internal state of header parser.
  17.  * (Empty the stomach of partially-digested headers.)
  18.  */
  19. void
  20. hdrwretch()
  21. {
  22.     /* historical stub */
  23. }
  24.  
  25. /*
  26.  * Parse RFC822/850/1036 header into "hdrs".  Retain significant values.
  27.  * Assumes ishdr has been called first.
  28.  *
  29.  * If a keyword matches one in hdrlst, store the value in *malloc'ed memory*
  30.  * (N.B.).  freeheader() will free this memory.
  31.  */
  32.  
  33. void hdrparse(hdrs, line, hdrlst)
  34. register struct headers *hdrs;
  35. register char *line;
  36. struct hdrdef *hdrlst[];            /* headers of positive utility */
  37. {
  38.     register struct hdrdef **hpp;
  39.  
  40.     for (hpp = hdrlst; *hpp != NULL; hpp++)
  41.         if (STREQN(line, (*hpp)->hdrnm, (int)(*hpp)->hdrlen) &&
  42.                 (*hpp)->hdroff >= 0) {    /* paranoia */
  43.             register char **ptrp = (char **)((char *)hdrs+(*hpp)->hdroff);
  44.  
  45.             nnfree(ptrp);    /* free prev. val. in this art. */
  46.             *ptrp = strsave(skipsp(&line[(*hpp)->hdrlen]));
  47.             if (*ptrp != NULL)
  48.                 trim(*ptrp);    /* cut trailing \n */
  49.             break;
  50.         }
  51. }
  52.  
  53. /*
  54.  * default missing header values
  55.  *
  56.  * If strsave ever returns NULL on failure, instead of exiting,
  57.  * then the strsave calls need to check for failure.
  58.  *
  59.  * We support control message *backwards* compatibility: if no Control:
  60.  * header exists and the newsgroup matches all.all.ctl, use the Subject:
  61.  * as the control message.  Ugh.
  62.  */
  63.  
  64. void hdrdeflt(hdrs)
  65. register struct headers *hdrs;
  66. {
  67.     if (hdrs->h_ngs == NULL)
  68.         hdrs->h_ngs = strsave(JUNK);
  69.     if (hdrs->h_distr == NULL)
  70.         hdrs->h_distr = strsave(DEFDIST);
  71.     if (hdrs->h_msgid == NULL && hdrs->h_artid != NULL)    /* obs. art.id. */
  72.         hdrs->h_msgid = strsave(hdrs->h_artid);
  73.     if (hdrs->h_msgid == NULL)
  74.         hdrs->h_msgid = strsave(DEFMSGID);
  75.     if (hdrs->h_msgid[0] == '\0') {
  76.         free(hdrs->h_msgid);
  77.         hdrs->h_msgid = strsave(DEFMSGID);
  78.     }
  79.     if (hdrs->h_expiry == NULL)
  80.         hdrs->h_expiry = strsave(DEFEXP);
  81.     if (hdrs->h_expiry[0] == '\0') {
  82.         free(hdrs->h_expiry);
  83.         hdrs->h_expiry = strsave(DEFEXP);
  84.     }
  85.     if (hdrs->h_subj == NULL)
  86.         hdrs->h_subj = strsave("");
  87.  
  88.     if (hdrs->h_ctlcmd == NULL && oldctl(hdrs))
  89.         hdrs->h_ctlcmd = strsave(hdrs->h_subj);
  90. }
  91.